﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace KFGame
{
    public class KFAutoLink
    {
        public int port = 8888;

        public KFAutoLink()
        {

        }
        public void Close()
        {

        }

        KFPing ping;
        public void checkedLinks()
        {
            Debug.Log("checkedLinks ");

            ping = new KFPing();
            ping.OnComplete += revectIPs;
            ping.Start();
        }

        //在线主机IP地址表
        public void revectIPs(List<string> ips)
        {
            ping.OnComplete -= revectIPs;

            Debug.Log("revect " + ips.Count);
            LinkServer(ips);
        }


        KFSocketClient autuclient;
        //测试并连接主机
        public void LinkServer(List<string> ips)
        {

            foreach (string ip in ips)
            {
                KFSocketClient client = new KFSocketClient();
                Debug.Log("connect " + ip);
                if (client.ConnectServer(ip, port))
                {
                    Debug.Log("connect   success");
                    autuclient = client;
                }
            }
            Debug.Log("  测试连接完成");
        }

    }

}